//-----------------------------------------------------------------------
// <copyright file="a_SEO_ContentDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_SEO_ContentDAOBase
    {
        #region Common methods
        public virtual a_SEO_Content Createa_SEO_ContentFromReader(IDataReader reader)
        {
            a_SEO_Content item = new a_SEO_Content();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("SID"))) item.SID = (int)reader["SID"];
                if (!reader.IsDBNull(reader.GetOrdinal("PageType"))) item.PageType = (byte)reader["PageType"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatMainID"))) item.CatMainID = (int)reader["CatMainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatSubID"))) item.CatSubID = (int)reader["CatSubID"];
                if (!reader.IsDBNull(reader.GetOrdinal("AdjWords"))) item.AdjWords = (int)reader["AdjWords"];
                if (!reader.IsDBNull(reader.GetOrdinal("DivHeight"))) item.DivHeight = (int)reader["DivHeight"];
                if (!reader.IsDBNull(reader.GetOrdinal("MainKeyword"))) item.MainKeyword = (string)reader["MainKeyword"];
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) item.Title = (string)reader["Title"];
                if (!reader.IsDBNull(reader.GetOrdinal("MetaKeywords"))) item.MetaKeywords = (string)reader["MetaKeywords"];
                if (!reader.IsDBNull(reader.GetOrdinal("MetaDesc"))) item.MetaDesc = (string)reader["MetaDesc"];
                if (!reader.IsDBNull(reader.GetOrdinal("H1"))) item.H1 = (string)reader["H1"];
                if (!reader.IsDBNull(reader.GetOrdinal("FirstSentencePart"))) item.FirstSentencePart = (string)reader["FirstSentencePart"];
                if (!reader.IsDBNull(reader.GetOrdinal("H2"))) item.H2 = (string)reader["H2"];
                if (!reader.IsDBNull(reader.GetOrdinal("Paragraph"))) item.Paragraph = (string)reader["Paragraph"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt1"))) item.ImgAlt1 = (string)reader["ImgAlt1"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt2"))) item.ImgAlt2 = (string)reader["ImgAlt2"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt3"))) item.ImgAlt3 = (string)reader["ImgAlt3"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt4"))) item.ImgAlt4 = (string)reader["ImgAlt4"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt5"))) item.ImgAlt5 = (string)reader["ImgAlt5"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt6"))) item.ImgAlt6 = (string)reader["ImgAlt6"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt7"))) item.ImgAlt7 = (string)reader["ImgAlt7"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt8"))) item.ImgAlt8 = (string)reader["ImgAlt8"];
                if (!reader.IsDBNull(reader.GetOrdinal("ImgAlt9"))) item.ImgAlt9 = (string)reader["ImgAlt9"];
                if (!reader.IsDBNull(reader.GetOrdinal("Comment1"))) item.Comment1 = (string)reader["Comment1"];
                if (!reader.IsDBNull(reader.GetOrdinal("Comment2"))) item.Comment2 = (string)reader["Comment2"];
                if (!reader.IsDBNull(reader.GetOrdinal("Comment3"))) item.Comment3 = (string)reader["Comment3"];
                if (!reader.IsDBNull(reader.GetOrdinal("Comment4"))) item.Comment4 = (string)reader["Comment4"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_SEO_Content methods
            
        public virtual void Createa_SEO_Content(a_SEO_Content a_SEO_Content)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Content_ins");
                
                database.AddInParameter(dbCommand, "@PageType", DbType.Byte, a_SEO_Content.PageType);
                database.AddInParameter(dbCommand, "@CatMainID", DbType.Int32, a_SEO_Content.CatMainID);
                database.AddInParameter(dbCommand, "@CatSubID", DbType.Int32, a_SEO_Content.CatSubID);
                database.AddInParameter(dbCommand, "@AdjWords", DbType.Int32, a_SEO_Content.AdjWords);
                database.AddInParameter(dbCommand, "@DivHeight", DbType.Int32, a_SEO_Content.DivHeight);
                database.AddInParameter(dbCommand, "@MainKeyword", DbType.String, a_SEO_Content.MainKeyword);
                database.AddInParameter(dbCommand, "@Title", DbType.String, a_SEO_Content.Title);
                database.AddInParameter(dbCommand, "@MetaKeywords", DbType.String, a_SEO_Content.MetaKeywords);
                database.AddInParameter(dbCommand, "@MetaDesc", DbType.String, a_SEO_Content.MetaDesc);
                database.AddInParameter(dbCommand, "@H1", DbType.String, a_SEO_Content.H1);
                database.AddInParameter(dbCommand, "@FirstSentencePart", DbType.String, a_SEO_Content.FirstSentencePart);
                database.AddInParameter(dbCommand, "@H2", DbType.String, a_SEO_Content.H2);
                database.AddInParameter(dbCommand, "@Paragraph", DbType.String, a_SEO_Content.Paragraph);
                database.AddInParameter(dbCommand, "@ImgAlt1", DbType.String, a_SEO_Content.ImgAlt1);
                database.AddInParameter(dbCommand, "@ImgAlt2", DbType.String, a_SEO_Content.ImgAlt2);
                database.AddInParameter(dbCommand, "@ImgAlt3", DbType.String, a_SEO_Content.ImgAlt3);
                database.AddInParameter(dbCommand, "@ImgAlt4", DbType.String, a_SEO_Content.ImgAlt4);
                database.AddInParameter(dbCommand, "@ImgAlt5", DbType.String, a_SEO_Content.ImgAlt5);
                database.AddInParameter(dbCommand, "@ImgAlt6", DbType.String, a_SEO_Content.ImgAlt6);
                database.AddInParameter(dbCommand, "@ImgAlt7", DbType.String, a_SEO_Content.ImgAlt7);
                database.AddInParameter(dbCommand, "@ImgAlt8", DbType.String, a_SEO_Content.ImgAlt8);
                database.AddInParameter(dbCommand, "@ImgAlt9", DbType.String, a_SEO_Content.ImgAlt9);
                database.AddInParameter(dbCommand, "@Comment1", DbType.String, a_SEO_Content.Comment1);
                database.AddInParameter(dbCommand, "@Comment2", DbType.String, a_SEO_Content.Comment2);
                database.AddInParameter(dbCommand, "@Comment3", DbType.String, a_SEO_Content.Comment3);
                database.AddInParameter(dbCommand, "@Comment4", DbType.String, a_SEO_Content.Comment4);
                database.AddOutParameter(dbCommand, "@SID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_SEO_Content.SID = (int)database.GetParameterValue(dbCommand, "@SID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_SEO_Content methods
        
        public virtual void Updatea_SEO_Content(a_SEO_Content a_SEO_Content)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Content_upd");            
                
                database.AddInParameter(dbCommand, "@SID", DbType.Int32, a_SEO_Content.SID);
                database.AddInParameter(dbCommand, "@PageType", DbType.Byte, a_SEO_Content.PageType);
                database.AddInParameter(dbCommand, "@CatMainID", DbType.Int32, a_SEO_Content.CatMainID);
                database.AddInParameter(dbCommand, "@CatSubID", DbType.Int32, a_SEO_Content.CatSubID);
                database.AddInParameter(dbCommand, "@AdjWords", DbType.Int32, a_SEO_Content.AdjWords);
                database.AddInParameter(dbCommand, "@DivHeight", DbType.Int32, a_SEO_Content.DivHeight);
                database.AddInParameter(dbCommand, "@MainKeyword", DbType.String, a_SEO_Content.MainKeyword);
                database.AddInParameter(dbCommand, "@Title", DbType.String, a_SEO_Content.Title);
                database.AddInParameter(dbCommand, "@MetaKeywords", DbType.String, a_SEO_Content.MetaKeywords);
                database.AddInParameter(dbCommand, "@MetaDesc", DbType.String, a_SEO_Content.MetaDesc);
                database.AddInParameter(dbCommand, "@H1", DbType.String, a_SEO_Content.H1);
                database.AddInParameter(dbCommand, "@FirstSentencePart", DbType.String, a_SEO_Content.FirstSentencePart);
                database.AddInParameter(dbCommand, "@H2", DbType.String, a_SEO_Content.H2);
                database.AddInParameter(dbCommand, "@Paragraph", DbType.String, a_SEO_Content.Paragraph);
                database.AddInParameter(dbCommand, "@ImgAlt1", DbType.String, a_SEO_Content.ImgAlt1);
                database.AddInParameter(dbCommand, "@ImgAlt2", DbType.String, a_SEO_Content.ImgAlt2);
                database.AddInParameter(dbCommand, "@ImgAlt3", DbType.String, a_SEO_Content.ImgAlt3);
                database.AddInParameter(dbCommand, "@ImgAlt4", DbType.String, a_SEO_Content.ImgAlt4);
                database.AddInParameter(dbCommand, "@ImgAlt5", DbType.String, a_SEO_Content.ImgAlt5);
                database.AddInParameter(dbCommand, "@ImgAlt6", DbType.String, a_SEO_Content.ImgAlt6);
                database.AddInParameter(dbCommand, "@ImgAlt7", DbType.String, a_SEO_Content.ImgAlt7);
                database.AddInParameter(dbCommand, "@ImgAlt8", DbType.String, a_SEO_Content.ImgAlt8);
                database.AddInParameter(dbCommand, "@ImgAlt9", DbType.String, a_SEO_Content.ImgAlt9);
                database.AddInParameter(dbCommand, "@Comment1", DbType.String, a_SEO_Content.Comment1);
                database.AddInParameter(dbCommand, "@Comment2", DbType.String, a_SEO_Content.Comment2);
                database.AddInParameter(dbCommand, "@Comment3", DbType.String, a_SEO_Content.Comment3);
                database.AddInParameter(dbCommand, "@Comment4", DbType.String, a_SEO_Content.Comment4);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_SEO_Content methods
        public virtual void Deletea_SEO_Content(int sid)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Content_del");
                
                database.AddInParameter(dbCommand, "@SID", DbType.Int32, sid);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_SEO_Content methods
        
        public virtual a_SEO_Content Geta_SEO_Content(int sid)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Content_sel");
                
                database.AddInParameter(dbCommand, "@SID", DbType.Int32, sid);
                
                a_SEO_Content a_SEO_Content =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_SEO_Content = Createa_SEO_ContentFromReader(reader);
                        reader.Close();
                    }
                }
                return a_SEO_Content;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_SEO_ContentByCatSub methods

        public virtual a_SEO_Content Geta_SEO_ContentByCatSub(int CatSubId)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Content_selByCatSub");

                database.AddInParameter(dbCommand, "@CatSubId", DbType.Int32, CatSubId);

                a_SEO_Content a_SEO_Content = null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_SEO_Content = Createa_SEO_ContentFromReader(reader);
                        reader.Close();
                    }
                }
                return a_SEO_Content;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Geta_SEO_ContentList methods
        public virtual a_SEO_ContentCollection Geta_SEO_ContentList(a_SEO_ContentColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Content_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_SEO_ContentCollection a_SEO_ContentCollection = new a_SEO_ContentCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_SEO_Content a_SEO_Content = Createa_SEO_ContentFromReader(reader);
                        a_SEO_ContentCollection.Add(a_SEO_Content);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_SEO_ContentCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_SEO_ContentCollection Geta_SEO_ContentList(a_SEO_ContentColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_SEO_ContentList(orderBy, orderDirection, 0, 0, out totalRecords);
        }

        public virtual a_SEO_Content Geta_SEO_ContentListByCatMainAndCatSub(int catMainID, int catSubID)
        {
            try
            {               
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_SEO_Content_selListByCatMainAndCatSub");

                database.AddInParameter(dbCommand, "@CatMainID", DbType.Int32, catMainID);
                database.AddInParameter(dbCommand, "@catSubID", DbType.Int32, catSubID);

                a_SEO_Content a_SEO_Content = null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_SEO_Content = Createa_SEO_ContentFromReader(reader);
                        reader.Close();
                    }
                }
                return a_SEO_Content;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion
    }
}